package com.lifeservice.console.controller;

import com.lifeservice.common.annotation.Log;
import com.lifeservice.common.core.controller.BaseController;
import com.lifeservice.common.core.domain.AjaxResult;
import com.lifeservice.common.core.page.TableDataInfo;
import com.lifeservice.common.enums.BusinessType;
import com.lifeservice.common.utils.poi.ExcelUtil;
import com.lifeservice.console.domain.LifeWorkClass;
import com.lifeservice.console.service.ILifeWorkClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 排班时间子Controller
 *
 * @author lifeservice
 * @date 2023-02-28
 */
@RestController
@RequestMapping("/console/class")
public class LifeWorkClassController extends BaseController {
    @Autowired
    private ILifeWorkClassService lifeWorkClassService;

    /**
     * 查询排班时间子列表
     */
    @GetMapping("/list")
    public TableDataInfo list(LifeWorkClass lifeWorkClass) {
        startPage();
        List<LifeWorkClass> list = lifeWorkClassService.selectLifeWorkClassList(lifeWorkClass);
        return getDataTable(list);
    }

    /**
     * 导出排班时间子列表
     */
    @Log(title = "排班时间子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LifeWorkClass lifeWorkClass) {
        List<LifeWorkClass> list = lifeWorkClassService.selectLifeWorkClassList(lifeWorkClass);
        ExcelUtil<LifeWorkClass> util = new ExcelUtil<LifeWorkClass>(LifeWorkClass.class);
        util.exportExcel(response, list, "排班时间子数据");
    }

    /**
     * 获取排班时间子详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(lifeWorkClassService.selectLifeWorkClassById(id));
    }

    /**
     * 新增排班时间子
     */
    @Log(title = "排班时间子", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LifeWorkClass lifeWorkClass) {
        return toAjax(lifeWorkClassService.insertLifeWorkClass(lifeWorkClass));
    }

    /**
     * 修改排班时间子
     */
    @Log(title = "排班时间子", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LifeWorkClass lifeWorkClass) {
        return toAjax(lifeWorkClassService.updateLifeWorkClass(lifeWorkClass));
    }

    /**
     * 删除排班时间子
     */
    @Log(title = "排班时间子", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(lifeWorkClassService.deleteLifeWorkClassByIds(ids));
    }
}
